#!/usr/bin/perl

#===============
# * 2013 Copyright Matthew Caswell
# * Pool.pl
#-------
# * Pool language translator/compiler.
# * P.O.O.L - Perl Object Oriented Language
#===============

# __START Perl
use strict;
use Data::Dumper;
use Switch;
# __END Perl

# __START NonPerl
use PoolCompiler::Stubs;
use PoolCompiler::Compiler;
# __END NonPerl

# __START Constants
use constant POOL_VERSION => "M10r01";
# __END Constants

# __START Compiler
my $POOL_VERSION = POOL_VERSION;

print "This is Pool/$POOL_VERSION\n";
print "2013 Copyright Matthew Caswell\n";

#== Switch processor
  
unless($#ARGV >= 1){
  die "Usage: $0 +[ecsgv] <class|startClassFunction|stub> [outclass|arguments|stubName]\n".
    " e - execute stub\n".
    " c - compile\n".
    " s - generate stub\n".
    " g - generate and execute stub\n".
    " v - version\n".
    " class - The path to the .pool class file\n".
    " outclass - target path where perl module will be placed\n".
    " startClassFunction - Function that a stub will call\n".
    " stub - Path to the perl script to execute\n".
    " arguments - arguments for a program started with Pool\n".
    " stubName - target path where the perl script (stub) will be placed\n";
}

my @sc = split '', $ARGV[0];

switch ($sc[1]){
  case "e" { PoolCompiler::Stubs::execute(@ARGV) }
  case "c" { PoolCompiler::Compiler::compile(@ARGV) }
  case "s" { PoolCompiler::Stubs::generate(@ARGV) }
  case "g" { PoolCompiler::Stubs::genExec(@ARGV) }
  case "v" { Version(POOL_VERSION) }
  else { PoolBadSwitch(@ARGV) }
}

#== Actual subroutines

# Version(POOL_VERSION) - Prints versioning info to STDOUT.
sub Version($){
  my $version = shift;
  die "Perl Object Oriented Language (POOL) version $version.\n".
    "Pool/$version 2013 Copyright Matthew Caswell\n";
}

# PoolBadSwitch(@ARGV) - Displays error message about switching
sub PoolBadSwitch(@){
  my @args = @_;
  
  die "Pool [:] ".$args[0]." [:] Bad switch\n";
}

# __END Compiler
